package com.qianfeng.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qianfeng.biz.IAddressBiz;
import com.qianfeng.biz.impl.AddressBizImpl;
import com.qianfeng.entity.Address;
import com.qianfeng.entity.User;

public class PayServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private IAddressBiz addressBiz = new AddressBizImpl();

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String action = request.getParameter("action");
		PrintWriter out = response.getWriter();
		if("checkLogin".equals(action)){
			//判断用户是否登录
			User user = (User) request.getSession().getAttribute("LOGIN_USER");
			if(user==null){
				out.write("<script>alert('您还未登录，请先进行登录');location.href='login.jsp'</script>");
			}else{
				//查询登录用户的收货地址
				int userid = user.getId();
				List<Address> addressList = addressBiz.getAddressListByUserId(userid);
				request.getSession().setAttribute("addressList", addressList);
				response.sendRedirect("pay.jsp");
			}
		}
	}

}
